//
//  DLDealBgView.m
//  delongzhitou
//
//  Created by Mr.Wang on 2018/12/19.
//  Copyright © 2018 delongzhitou. All rights reserved.
//

#import "DLDealBgView.h"
#import "DLDealListModel.h"
#import "DLDealTC.h"

@implementation DLDealBgView


- (instancetype) initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        
        UITableView *dealTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height) style:UITableViewStylePlain];
        dealTableView.delegate = self;
        dealTableView.dataSource = self;
        dealTableView.rowHeight = 84;
        [self addSubview:dealTableView];
        self.dealTableView = dealTableView;
        
        [dealTableView registerClass:[DLDealTC class] forCellReuseIdentifier:@"DLDealTC"];
        
        dealTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            
            [[NSNotificationCenter defaultCenter] postNotificationName:@"DLreloadNewDealData" object:nil];
        }];
        
        dealTableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
            
            [[NSNotificationCenter defaultCenter] postNotificationName:@"DLloadMoreDealData" object:nil];
        }];
        
    }
    return self;
}

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    NSLog(@"分区数：%ld", self.dealViewDataSource.count);
    return self.dealViewDataSource.count;
}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    DLDealTC *cell = [tableView dequeueReusableCellWithIdentifier:@"DLDealTC"];
    
    DLDealListModel *model = self.dealViewDataSource[indexPath.row];
    cell.dealModel = model;
    
    return cell;
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


- (void) setdealViewDataSource:(NSArray *)dealViewDataSource {
    _dealViewDataSource = dealViewDataSource;
    //    NSLog(@"infoView里面，文章列表的数据是%@", dealViewDataSource);
    [self.dealTableView reloadData];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
